package com.group.www.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.www.dao.impl.OutgoingInfoDao;
import com.group.www.interfaces.OutgoingInfoServiceI;
import com.group.www.pojo.OutgoingInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@com.alibaba.dubbo.config.annotation.Service
@Service
public class SimpleOutgoingInfoService implements OutgoingInfoServiceI {

    @Autowired
    private OutgoingInfoDao outgoingInfoDao;

    @Override
    public boolean add(OutgoingInfo entity) {
        outgoingInfoDao.save(entity);
        return true;
    }

    @Override
    public boolean update(OutgoingInfo entity) {
        this.outgoingInfoDao.update(entity);
        return false;
    }

    @Override
    public List<OutgoingInfo> query() {
        return outgoingInfoDao.query();
    }

    @Override
    public boolean delete(OutgoingInfo entity) {
        outgoingInfoDao.delete(entity);
        return true;
    }

    @Override
    public boolean deleteMany(String ids) {
        if("".equals(ids)||ids==null){
            return false;
        }
        for (String id : ids.split(",")) {
            OutgoingInfo outgoingInfo = new OutgoingInfo();
            outgoingInfo.setGoodsid(Integer.parseInt(id));
            this.delete(outgoingInfo);
        }
        return true;
    }

    @Override
    public OutgoingInfo queryById(int id) {
        return this.outgoingInfoDao.queryById(id);
    }

    @Override
    public PageInfo<OutgoingInfo> queryAllByBrandId(Integer brandid, Integer pageIndex, Integer pageSize, Object goodsname) {
        PageHelper.startPage(pageIndex,pageSize);
        List<OutgoingInfo> outgoingInfos = this.outgoingInfoDao.queryAllByBrandId(brandid, goodsname);
        return new PageInfo<>(outgoingInfos);
    }
}
